package com.desire.homework;

import java.util.Calendar;
import java.util.Date;

public class _06_各种方法输出星期几 {
    public static void main(String[] args) {
        Date date = new Date();
        int day = date.getDay();
        if (day == 0) System.out.println("星期日");
        if (day == 1) System.out.println("星期一");
        if (day == 2) System.out.println("星期二");
        if (day == 3) System.out.println("星期三");
        if (day == 4) System.out.println("星期四");
        if (day == 5) System.out.println("星期五");
        if (day == 6) System.out.println("星期六");

        //改进代码  使用if else
        if (day == 0) {
            System.out.println("星期日");
        } else if (day == 1) {
            System.out.println("星期一");
        } else if (day == 2) {
            System.out.println("星期二");
        } else if (day == 3) {
            System.out.println("星期三");
        } else if (day == 4) {
            System.out.println("星期四");
        } else if (day == 5) {
            System.out.println("星期五");
        } else {
            System.out.println("星期六");
        }

        //再次改进 switch case 语句
        Calendar calendar = Calendar.getInstance();
        int days = calendar.get(Calendar.DAY_OF_WEEK);
        switch (days) {
            case 0:
                System.out.println("星期日");
                break;
            case 1:
                System.out.println("星期一");
                break;
            default:
                System.out.println("星期" + new Date().getDay());
        }

        //再次改进 直接输出
        Calendar c = Calendar.getInstance();
        int d = calendar.get(Calendar.DAY_OF_WEEK) - 1;
        System.out.println("今天是:星期" + "日一二三四五六".charAt(d));

        //或者
        System.out.printf("今日是：%tA%n", System.currentTimeMillis());
    }
}
